package site.addzero.addl.action.autoddlwithdb.scanner

import site.addzero.addl.action.autoddlwithdb.scanner.EntityAnnotationChecker.Companion.ENTITY_ANNOTATIONS
import site.addzero.util.lsi.clazz.LsiClass
import site.addzero.util.lsi.impl.kt.KtLsiClass
import site.addzero.util.lsi.impl.psi.PsiLsiClass
import com.intellij.psi.PsiClass
import org.jetbrains.kotlin.psi.KtClass


interface EntityAnnotationChecker<T> {
    fun isEntityClass(clazz: T): Boolean

}

class KotlinEntityAnnotationChecker : EntityAnnotationChecker<KtClass> {
    override fun isEntityClass(clazz: KtClass): Boolean {
        val lsiClass: LsiClass = KtLsiClass(clazz)
        val any = ENTITY_ANNOTATIONS.any {
            lsiClass.hasAnnotation(it)
        }
        return any
    }
}

class JavaEntityAnnotationChecker : EntityAnnotationChecker<PsiClass> {
    override fun isEntityClass(clazz: PsiClass): Boolean {
        val lsiClass: LsiClass = PsiLsiClass(clazz)
        val any = ENTITY_ANNOTATIONS.any {
            lsiClass.hasAnnotation(it)
        }
        return any
    }
}
